package com.ligq.vbasedemo

import org.junit.Test

class GLBTest {
    /**
     * 哥伦布解码
     */
    @Test
    fun testDec() {
        val data = 5 and 0xff//0000 0101,需要从00101开始读
        var bitStart = 3
        var zeroNum = 0
        //统计出现0的个数
        (0x1F shr bitStart)
        while (bitStart < 8) {
            if (data and ((0x80 shr bitStart)) != 0) {
                break
            }
            bitStart++
            zeroNum++
        }
        println("zero num:${zeroNum}")
        bitStart++
        //计算右边的数据101
        val value: Int
        var dwRet = 0
        for (i in 0 until zeroNum) {
            dwRet = dwRet shl 1
            if (data and (0x80 shr (bitStart % 8)) != 0) {
                dwRet += 1
            }
            bitStart++
        }
        value = (1 shl zeroNum) + dwRet - 1
        println("value:${value}")

    }
}